Download
FAQ
History
HomeHomeNext API
Search
Feedback
Divider

What Is a JSP Page?

A JSP page is a text document that contains two types of text: static template data, which can be expressed in any text-based format, such as HTML, SVG, WML, and XML, and JSP elements, which construct dynamic content.

The JSP elements in a JSP page can be expressed in two syntaxes: standard and XML, though an individual page can only use one syntax. A JSP page in XML syntax is an XML document and can be manipulated by tools and APIs for XML documents. The chapters in this tutorial that cover JSP technology currently document only the standard syntax. The XML syntax will be addressed in a future release of the tutorial. A syntax card and reference that summarizes both syntaxes is available at

http://java.sun.com/products/jsp/docs.html#syntax 

Example

The Web page in Figure 12-1 is a form that allows you to select a locale and displays the date in a manner appropriate to the locale.

Localized Date Form

Figure 12-1 Localized Date Form

The source code for this example is in the <INSTALL>/j2eetutorial14/examples/web/date/ directory. The JSP page, index.jsp, used to create the form appears below; it is a typical mixture of static HTML markup and JSP elements. If you have developed Web pages, you are probably familiar with the HTML document structure statements (<head>, <body>, and so on) and the HTML statements that create a form (<form>) and a menu (<select>).

The lines in bold in the example code contain the following types of JSP constructs:

A sample date.war is provided in <INSTALL>/j2eetutorial14/examples/web/provided-wars/. To build, package, deploy, and execute this example:

  1. In a terminal window, go to <INSTALL>/j2eetutorial14/examples/web/date/.
  2. Run asant build. This target will spawn any necessary compilations and copy files to the <INSTALL>/j2eetutorial14/examples/web/date/build directory.
  3. Start the J2EE application server.
  4. Start deploytool.
  5. Create a Web application called date by running the New Web Application Wizard. Select FileRight ArrowNewRight ArrowWeb Application WAR.
  6. New Web Application Wizard
    1. Select the Create New Stand-Alone WAR Module radio button.
    2. Click Browse and in the file chooser, navigate to <INSTALL>/docs/tutorial/examples/web/date/.
    3. In the File Name field, enter date.
    4. Click Choose Module File.
    5. In the WAR Display Name field, enter date.
    6. In the Deployment Setting frame, set the Context Root field value to /date.
    7. Click Edit.
    8. In the Edit Contents dialog, navigate to <INSTALL>/docs/tutorial/examples/web/date/build/. Select the index.jsp and date.jsp JSP pages and the mypkg package and click Add, then click OK.
    9. Click Next.
    10. Select the JSP radio button.
    11. Click Next.
    12. Select index.jsp from the JSP file combo box.
    13. Click Finish.
  7. Select FileRight ArrowSave.
  8. Deploy the application.
    1. Select ToolsRight ArrowDeploy.
    2. In the Connection Settings frame, enter the user name and password you specified when you installed the J2EE 1.4 Application Server.
    3. Click OK.
    4. A popup dialog will display the results of the deployment. Click Close.
  9. Set the character encoding in your browser to UTF-8.
  10. Open the URL http://localhost:1024/date in a browser.

You will see a combo box whose entries are locales. Select a locale and click Get Date. You will see the date expressed in a manner appropriate for that locale.

Divider
Download
FAQ
History
HomeHomeNext API
Search
Feedback
Divider

All of the material in The J2EE 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.